var areaUser = {
	
	roleEnNames: new Array(),
		
	hashMap : new HashMap(),
	
	cacheHashMap : new HashMap(),
	
	/**
	 * 初始化数据
	 */
    init : function(){
    	areaUser.initRole("roleSelect",0);//初始化角色下拉列表
    	//areaUser.initDepartment(0);
    	areaUser.selRole(false);//初始化第一个角色的权限
    	areaUser.initSubject("subjectSelect");
    	areaUser.initStuPhase("phaseSelect");
//    	$('#multiIdentitySelector').hide();
	},
	
	initSubject: function(selectId) {
		var data = areaUser.ajax("manage/areaUser_getSubjects.action?rdm="+Math.random());
		var obj = areaUser.getObj(selectId);
		data = eval(data);
		for(var i=0;i<data.length;i++){
			obj.options.add(new Option(data[i].name,data[i].code)); 
        }
	},
	
	initStuPhase: function(selectId) {
		var data = areaUser.ajax("manage/areaUser_getStuPhases.action?rdm="+Math.random());
		var obj = areaUser.getObj(selectId);
		data = eval(data);
		for(var i=0;i<data.length;i++){
			obj.options.add(new Option(data[i].name,data[i].code)); 
        }
	},
	
	confirmsubandphase : function() {
    	var resultDiv = areaUser.getObj("showSubjectAndPhase");
		var subjectTxt = $("#subjectSelect option:selected").text(); 
		var phaseTxt = $("#phaseSelect option:selected").text();
		var subjectVal = $("#subjectSelect option:selected").val();
		var phaseVal = $("#phaseSelect option:selected").val();
		var subjectTxtSub="";
		// 如果空不能在添加
		if(subjectVal==""||phaseVal==""||subjectTxt==""||phaseTxt==""){
			return ;
		}
		var len = $('.subjectandphases').length;
		if (len > 0) {
			var subject = $("#subjectSelect option:selected").text();
			var subandphase = '';
			$('.subandphaseresult').each(function(index, cur) {
				var v = $(cur).attr('code');
				subandphase = subandphase + v + ',';
			});
			var index=subandphase.indexOf(phaseVal+"-"+subjectVal);
			if(index>=0){
				alert("不能重复添加学段和学科信息！");
				return;
			}
			if(subjectTxt.length>10){
				subjectTxtSub = subjectTxt.substring(0,10)+"...";
			}else{
				subjectTxtSub = subjectTxt;
			}
		}else{
			if(subjectTxt.length>10){
				subjectTxtSub = subjectTxt.substring(0,10)+"...";
			}else{
				subjectTxtSub = subjectTxt;
			}
		}
		
		
		
		var inner = '<div class="subjectandphases">'+
                                  '<div style="width:100px;height:30px;float:right"><a style="color:#0080C0;" href="javascript:void(0)" onclick="areaUser.delsubandphase(this)">删除</a></div>'+
                                  '<div style="width:250px;height:30px;"><a '+'style="color:#0080C0;"'+'code="'+phaseVal+'-'+subjectVal+'"'+'title="'+phaseTxt+'-'+subjectTxt+'"'+' class="subandphaseresult" href="javascript:void(0)" onclick="teacher.showTheRoleRightList(this)">'+phaseTxt+'-'+subjectTxtSub+'</a></div>'+
                                  '</div>';
		resultDiv.innerHTML = resultDiv.innerHTML + inner;
    },
    
    delsubandphase : function(obj) {
    	var len = $('.subjectandphases').length;
    	if (len > 1) {
    		$(obj).parent().parent().remove();
    	} else {
    		areaUser.showTishiDiv("提示","不允许删除，至少保留一个学段和学科!");
    	}
    },
	
	/**
	 * 修改时初始化数据
	 */
	modifyInit : function(){
		//areaUser.initDepartment(1);
		//areaUser.modifyDepartment();
		areaUser.initRole('roleSelect',1);
		areaUser.initRoleInfo();
//		areaUser.initRoleRightModify();
		areaUser.modifyInitPhoneAndEmail();
		areaUser.initSubject("subjectSelect");
    	areaUser.initStuPhase("phaseSelect");
	},
	
	
	/**
	 * 初始化单位角色列表 type 0新增  1修改
	 */
	initRole : function(selectId,type){
		var data = areaUser.ajax("manage/areaUser_getRole.action?type="+type+"&rdm="+Math.random());
        if(data == null){
           alert("无法找到对应的角色列表数据!");
           location.href = "manage/areaUser_list.action";
           return;
        }
         data = eval(data);
         var roleSelect = areaUser.getObj(selectId);
         for(var i=0;i<data.length;i++){
         	roleSelect.options.add(new Option(data[i].roleName,data[i].roleId)); 
         }
         
       /*  //根据角色 初始化权限
         areaUser.selRole();*/
	},
	
	//获取用户已选角色
	getUserSelectedRoles : function(){
		var data = areaUser.ajax("manage/areaUser_getUserSelectedRoles.action?rdm="+Math.random());
		if(data == null){
           //areaUser.showTishiDiv("提示","无法获取该用户的角色信息!");
           return;
        }
         data = eval(data);
         var roleDiv = areaUser.getObj("roleDiv");
         var inner = "";
         for(var i=0;i<data.length;i++){
         	  inner += '<input disabled checked type="checkbox" style="margin-left:10px;" id="cb_role'+data[i].roleId+'" name="role" value="'+data[i].roleId+'"><span style="margin-left:5px;">'+data[i].roleName+'</span>';
         }
         roleDiv.innerHTML = inner;
	},
	
	/**
	 * 初始化单位下的部门信息 type 0新增  1修改 2查看
	 */
	initDepartment : function(type){
		if(areaUser.getObj("deptDiv") == null)
		    return ;
		 
		var data = areaUser.ajax("manage/areaUser_getInitDepartment.action?rdm="+Math.random());
		if(data == null){
           //areaUser.showTishiDiv("提示","无法获取该单位的部门信息!");
           return;
        }
        data = eval(data);
         var deptDiv = areaUser.getObj("deptDiv");
         var inner = "";
         var disabled = "";
         if(type == 2)
            disabled = "disabled";
         for(var i=0;i<data.length;i++){
         	if(i==0 && type==0)
              inner += '<input '+disabled+' type="checkbox" checked id="cb_dep'+data[i].dmId+'" name="department" value="'+data[i].dmId+'"><span style="margin-left:5px;">'+data[i].dmName+'</span>';
         	else
         	  inner += '<input '+disabled+' type="checkbox" style="margin-left:10px;" id="cb_dep'+data[i].dmId+'" name="department" value="'+data[i].dmId+'"><span style="margin-left:5px;">'+data[i].dmName+'</span>';
         }
         deptDiv.innerHTML = inner;
	},
	
	/**
	 * 修改时  初始化选中部门
	 */
	modifyDepartment : function(){
		if(areaUser.getObj("deptDiv") == null)
		    return ;
		var data = areaUser.ajax("manage/areaUser_getModifyDepartment.action?rdm="+Math.random());
		//alert(data);
		if(data == null){
           //areaUser.showTishiDiv("提示","无法获取该单位的部门信息!");
           return;
        }
        departMentIdArr = data.split(",");
        for(var i=0;i<departMentIdArr.length;i++){
        	var cb = areaUser.getObj("cb_dep"+departMentIdArr[i]);
        	if(cb != null)
               cb.checked = true;
        }
	},
	
	
	/**
	 * 选择角色
	 */
	selRole : function (flag){
		var select = areaUser.getObj("roleSelect");
		var showResultDiv = areaUser.getObj("showResultDiv");
		
		var data = areaUser.isShowTeacherTjDiv(select.value);

		var check = areaUser.getObj("selectedRole_"+select.value);
		if(check == null){
			areaUser.roleEnNames.splice(0,areaUser.roleEnNames.length);
			areaUser.roleEnNames.push(select.value);
			var inner = '<div id="selectedRole_'+select.value+'">'+
		           '<div style="width:100px;height:30px;float:right;"><a style="color:#0080C0;"  href="javascript:void(0)" onclick="areaUser.delSelectedRole(this)">删除</a></div>'+
		           '<div style="width:250px;height:30px;"><a '+(data.isTeacher ? 'style="color:#0080C0;"' :'style="color:#000000;"')+' '+(data.isTeacher?'title="查看该角色权限"' :'title="'+select.options[select.selectedIndex].text+'"')+' href="javascript:void(0)" onclick="areaUser.showTheRoleRightList(this)">'+areaUser.subShow(select.options[select.selectedIndex].text,15)+'</a></div>'+
		        '</div>';
			showResultDiv.innerHTML = showResultDiv.innerHTML + inner;
		}
		    
	},
	
	setMultiIdentity:function(obj,pageFlg) {
		var userId = areaUser.getTrIndex(obj);
//		$("#list_iframe").attr("src","manage/areaUser_setMultiIdentity.action?userId="+userId+"&pageFlg="+pageFlg+"&rdm="+Math.random());
		location.href = "manage/areaUser_setMultiIdentity.action?userId="+userId+"&pageFlg="+pageFlg+"&rdm="+Math.random();
	},
	
	setMultiIdentityFromPage:function(obj) {
		var userId = $('#existedUserId').val();
		if (userId != null) {
			location.href = "manage/areaUser_setMultiIdentity.action?userId="+userId+"&rdm="+Math.random();			
		}
	},
	
	initwsSelect : function(data){
		areaUser.getObj("gradeSelect").style.display = "block";
		areaUser.getObj("subjectSelect").style.display = "block";
		areaUser.getObj("editionSelect").style.display = "block";
		areaUser.getObj("volumeSelect").style.display = "block";
		
		areaUser.getObj("gradeSelDiv").style.display = "block";
		areaUser.getObj("subjectSelDiv").style.display = "block";
		areaUser.getObj("editionSelDiv").style.display = "block";
		areaUser.getObj("volumeSelDiv").style.display = "block";
		
		if(data.grade == null || !data.grade){
		   areaUser.getObj("gradeSelect").style.display = "none";
		   areaUser.getObj("gradeSelDiv").style.display = "none";
		}
		if(data.subject == null || !data.subject){
		   areaUser.getObj("subjectSelect").style.display = "none";
		   areaUser.getObj("subjectSelDiv").style.display = "none";
		}
		if(data.publisher == null || !data.publisher){
		   areaUser.getObj("editionSelect").style.display = "none";
		   areaUser.getObj("volumeSelect").style.display = "none";
		   areaUser.getObj("editionSelDiv").style.display = "none";
		   areaUser.getObj("volumeSelDiv").style.display = "none";
		}
		areaUser.showDiv("wsinfoDiv");
	},
	
	/**
	 * 加载角色的权限集合
	 * param 是否重新请求数据库加载  false 从内存取数据加载  true重新请求数据库
	 */
	loadOrgRoleRight : function (isReload){
		var select = this.getObj("roleSelect");
		var org_role_id = select.value;
		var data = [];
//		var data = areaUser.ajax("manage/areaUser_getRoleRight.action?org_role_id="+org_role_id+"&rdm="+Math.random());
		//alert(data);
//        if(data == null){
//           areaUser.showTishiDiv("提示","该角色无对应的权限数据!");
//           return;
//        }
		var rightArr = new Array();
		var rightListDiv = document.getElementById("rightListDiv");
		rightListDiv.style.display=none;
		//alert(data);
		/**
	    data = eval(data);
		var inner = "";
		for(var i=0;i<data.length;i++){
			     if(isReload){
			     	inner += '<div><p><input type="checkbox" id="'+data[i].id+'" checked style="margin-right:5px;" onclick="areaUser.clickRoleRightModel(this)">'+data[i].name+'</p><p style="margin-left:20px;">';
			        rightArr.push(data[i].id);
			     }else{
			     	inner += '<div><p><input type="checkbox" id="'+data[i].id+'" '+areaUser.filterRoleRight(data[i].id)+' style="margin-right:5px;" onclick="areaUser.clickRoleRightModel(this)">'+data[i].name+'</p><p style="margin-left:20px;">';
			     }
			
		         var children = data[i].children;
		         for(var k=0;k<children.length;k++){
		         	if(isReload){//读取数据库数据
		         	   var checked = "checked";
		         	   if(children[k].enable != null && children[k].enable == false)//修改页面 enable为false
		         	   	    checked = "";
		         	   else//是新增页面或者修改页面时enable为true
		         	        rightArr.push(children[k].id);
		         	   inner += '<input '+checked+' name="rightList" value="'+children[k].id+'" onclick="areaUser.clickRoleRight(this)"  type="checkbox" style="margin-right:5px;">'+children[k].name+'&nbsp;&nbsp;&nbsp;&nbsp;';
		         	}
		         	else{//读取hashmap内存数据
		         	   inner += '<input '+areaUser.filterRoleRight(children[k].id)+' name="rightList" value="'+children[k].id+'" onclick="areaUser.clickRoleRight(this)"  type="checkbox" style="margin-right:5px;">'+children[k].name+'&nbsp;&nbsp;&nbsp;&nbsp;'
		         	}
		         }
		         inner += '</p></div>';
		}
		*/
		//更新内存选择的角色权限id数据
		if(isReload)
		    areaUser.hashMap.put("orgRole_"+select.value,rightArr);
		
		//更新显示区
//		rightListDiv.innerHTML = inner;
		
		//if(isReload)
//		    areaUser.initCheckIsAllUncheck();
    	
		   
	},
	
	
	/**
	 * 修改用户时初始化角色权限信息
	 */
	initRoleRightModify : function(){
		var data = areaUser.ajax("manage/areaUser_getRoleRightModify.action?rdm="+Math.random());
		//alert(data);
		if(data == null){
			areaUser.showTishiDiv("提示","无法获取该用户对应的权限数据");
			return;
		}
		data = eval(data);
		var showResultDiv = areaUser.getObj("showResultDiv");
		var inner = "";
		for(var i=0;i<data.length;i++){
			var roleId = data[i].roleId; 
			areaUser.roleEnNames.push(roleId);
			if(!areaUser.selectHaveTheValue(roleId))
			    continue;
			    
			var wsRoleData = areaUser.isShowTeacherTjDiv(roleId);
			var roleName = data[i].roleName;
		    inner += '<div id="selectedRole_'+roleId+'">'+
		           '<div style="width:100px;height:30px;float:right"><a style="color:#0080C0;" href="javascript:void(0)" onclick="areaUser.delSelectedRole(this)">删除</a></div>'+
		           '<div style="width:250px;height:30px;"><a  '+(wsRoleData.isTeacher ? 'style="color:#0080C0;"' :'style="color:#000000;"')+' '+(wsRoleData.isTeacher?'title="查看该角色权限"' :'title="'+roleName+'"')+' href="javascript:void(0)" onclick="areaUser.showTheRoleRightList(this)">'+areaUser.subShow(roleName,15)+'</a></div>'+
		        '</div>';
		        
		    if(i == 0){//默认已选中的第一个角色为下拉框当前选中角色
		    	var select = areaUser.getObj("roleSelect");
				for(var k=0;k<select.options.length;k++){
		     		if(select.options[k].value == roleId){
		     			select.options[k].selected = 'selected';
		     			break;
		     		}
		     	}
		    }
		}
		showResultDiv.innerHTML = showResultDiv.innerHTML + inner;
		//areaUser.hashMap.put("orgRole_"+select.value,rightArr);
		/**
		for(var i=0;i<data.length;i++){
			var roleId = data[i].roleId; 
			if(!areaUser.selectHaveTheValue(roleId))
			    continue;
	        var rights = data[i].rights;
	        var rightArr = new Array();
			for(var j=0;j<rights.length;j++){
		         var children = rights[j].children;
		         for(var k=0;k<children.length;k++){
		         	 if(children[k].enable == true){
		         	     rightArr.push(children[k].id);
		         	 }
		         }
		         if(!areaUser.haveTheSame(rightArr,rights[j].id))//加入模块id
		         	        rightArr.push(rights[j].id);
			}
			areaUser.hashMap.put("orgRole_"+data[i].roleId,rightArr);
		}
		*/
		
		areaUser.selRole(false);
		
		//areaUser.initRoleInfo();
	},
	
	/**
	 * 初始化课程信息
	 */
	initRoleInfo : function(){
		var data = areaUser.ajax("manage/areaUser_getRoleInfo.action?rdm="+Math.random());
		//alert(data);
        if(data == null){
           //areaUser.showTishiDiv("提示","无法找到对应的角色课程信息!");
           return;
        }
        
        data = eval(data);
        for(var i=0;i<data.length;i++){
        	var roleId = data[i].roleId;
        	if(!areaUser.selectHaveTheValue(roleId))
        	    continue;
        	var roleInfoArr = new Array();
        	var children = data[i].children;
        	for(k=0;k<children.length;k++){
        		roleInfoArr.push(children[k].grade+"'"+children[k].subject+"'"+children[k].edition+"'"+children[k].volume);
        	}
        	areaUser.hashMap.put("roleInfo_"+roleId,roleInfoArr);
        }
	},
	
	
	/**
	 * 判断当前角色列表中有无该角色
	 * @param {} roleId
	 * @return {}
	 */
	selectHaveTheValue : function(roleId){
		var select = areaUser.getObj("roleSelect");
		var isHave = false;
		for(var i=0;i<select.options.length;i++){
			if(select.options[i].value == roleId){
				isHave = true;
				break;
			}
		}
		return isHave;
	},
	
	
	/**
	 * 判断一个数组中是否有相同的元素
	 * @param {} arr 数组
	 * @param {} child 要添加的元素
	 * @return {Boolean}
	 */
	haveTheSame : function(arr,child){
		for(var i=0;i<arr.length;i++){
			if(arr[i] == child)
			   return true;
		}
		return false;
	},
	
	
	/**
	 * 新添加一条学制信息(角色完善信息)
	 */
	addInfo : function (){
		var grade = areaUser.getObj("gradeSelect");
		var subject = areaUser.getObj("subjectSelect");
		var edition = areaUser.getObj("editionSelect");
		var volume = areaUser.getObj("volumeSelect");
		
		var gradeV = 0, subjectV = 0,editionV = 0,volumeV = 0;
		var gradeT = "",subjectT = "",editionT = "",volumeT = "";
		
		if(grade.style.display == "block"){
		    gradeV = grade.value;
		    gradeT = grade.options[grade.selectedIndex].text;
		}
		if(subject.style.display == "block"){
		    subjectV = subject.value;
		    subjectT = subject.options[subject.selectedIndex].text
		}
		if(edition.style.display == "block"){
		    editionV = edition.value;
		    volumeV = volume.value;
		    editionT = edition.options[edition.selectedIndex].text;
		    volumeT = volume.options[volume.selectedIndex].text
		}
		
		
		var id = "info_"+gradeV+"'"+subjectV+"'"+editionV+"'"+volumeV;
		if(areaUser.getObj(id) != null)
		    return;
		    
		var select = this.getObj("roleSelect");    
		var roleInfoArr = areaUser.hashMap.get("roleInfo_"+select.value,false);
		if(roleInfoArr == null)
		    roleInfoArr = new Array();
		roleInfoArr.push(id.substring(5));
		areaUser.hashMap.put("roleInfo_"+select.value,roleInfoArr);
		 
		var text = gradeT+'&nbsp;'+subjectT+'&nbsp;'+
		        editionT+'&nbsp;'+volumeT;
		var showInfoDiv = areaUser.getObj("showInfoDiv");
		var inner = '<div style="margin-top:5px;background-color:#EEEEEE;">'+text+'<button type="button" id="'+id+'" onclick="areaUser.delInfo(this)" class="close"  data-dismiss="modal" title="删除" aria-hidden="true">×</button> </div>';
		showInfoDiv.innerHTML = showInfoDiv.innerHTML + inner;
	},
	
	/**
	 * 删除一条学制信息(角色完善信息)
	 */
	delInfo : function (obj){
		var padiv = obj.parentNode;
		areaUser.getObj("showInfoDiv").removeChild(padiv);
		
		var select = areaUser.getObj("roleSelect");    
		var roleInfoArr = areaUser.hashMap.get("roleInfo_"+select.value,false);
		if(roleInfoArr == null)
		    return;
		    
		for(var i=0;i<roleInfoArr.length;i++){
			if(roleInfoArr[i] == obj.id.substring(5)){
				roleInfoArr.splice(i,1);
				if(roleInfoArr.length == 0)
				    areaUser.hashMap.del("roleInfo_"+select.value);
				break;
			}
		}
		if(roleInfoArr.length > 0)
		    areaUser.hashMap.put("roleInfo_"+select.value,roleInfoArr);
		
	},
	/**
	 * 根据选择的角色  显示其已选择的学制信息(角色完善信息)
	 */
	loadRoleInfo : function(){
	    var select = this.getObj("roleSelect");
		var roleInfo = areaUser.hashMap.get("roleInfo_"+select.value,false);
		if(roleInfo == null){
			areaUser.getObj("showInfoDiv").innerHTML = "";
		    return;
		}
		var inner = "";
		for(var i=0;i<roleInfo.length;i++){
			var values = roleInfo[i].split("'");
			var id = "info_"+roleInfo[i];
			var text = areaUser.SelGetTextByValue(values[0],"gradeSelect")+"&nbsp;"+
			           areaUser.SelGetTextByValue(values[1],"subjectSelect")+"&nbsp;"+
			           areaUser.SelGetTextByValue(values[2],"editionSelect")+"&nbsp;"+
			           areaUser.SelGetTextByValue(values[3],"volumeSelect");
			inner += '<div style="margin-top:5px;background-color:#EEEEEE;">'+text+'<button type="button" id="'+id+'" onclick="areaUser.delInfo(this)" class="close"  data-dismiss="modal" title="删除" aria-hidden="true">×</button> </div>';
		}
		
		areaUser.getObj("showInfoDiv").innerHTML = inner;
	},
	
		/**
	 * 根据角色id是否显示完善信息div
	 * @param {} roleId 角色id
	 * @return {}
	 */
	isShowTeacherTjDiv : function (roleId){
		if(roleId.length == 0)
			return ;
		var data = areaUser.ajax("manage/areaUser_getRoleIsTeacher.action?roleId="+roleId+"&rdm="+Math.random());
		data = eval('(' + data + ')');
		if(!data.isTeacher)
//		    areaUser.closeInfoDiv();
		return data;
	},
	
	/**
	 * 关闭学制信息div
	
	
	closeInfoDiv : function (){
		 var div = document.getElementById("wsinfoDiv");
	     div.style.display = "none";
	},
	 */
	
	/**
	 * 显示 点击已选择的权限列表
	 * @param {} obj
	 */
	showTheRoleRightList : function (obj){
		var theDiv = obj.parentNode.parentNode;
		var showRoleId = theDiv.id.split("_")[1];//要显示的角色id
		areaUser.showNowRoleAndRightList(showRoleId);
		
		//根据角色id判断是否显示显示学段、学科div
		/*if(areaUser.isShowTeacherTjDiv(showRoleId)){
			areaUser.loadRoleInfo();
			areaUser.showDiv("wsinfoDiv");
		}*/
		var data = areaUser.isShowTeacherTjDiv(showRoleId);
		if(data.isTeacher){
			areaUser.loadRoleInfo();
			areaUser.initwsSelect(data);
		}
		
	},
	
	
	/**
	 * 根据角色id显示选择的权限列表
	 * @param roleId 角色id
	 */
	showNowRoleAndRightList : function (roleId){
		var select = areaUser.getObj("roleSelect");
		for(var i=0;i<select.options.length;i++){
     		if(select.options[i].value == roleId){
     			select.options[i].selected = 'selected';
     			areaUser.loadOrgRoleRight(false);
     			break;
     		}
     	}
	},
	
	/**
	 * 删除已选择的角色
	 */
	delSelectedRole : function (obj){
		var theDiv = obj.parentNode.parentNode;
		var delRoleId = theDiv.id.split("_")[1];//删除的角色id
		var showResultDiv = areaUser.getObj("showResultDiv");
		if(showResultDiv.childNodes.length > 1){
			  //内存数据相应的删除
		     areaUser.hashMap.del("orgRole_"+delRoleId);//删除对应的权限
		     areaUser.hashMap.del("roleInfo_"+delRoleId);//删除已选择的信息
		     //更新显示区
		     showResultDiv.removeChild(theDiv);
		     if(areaUser.getObj("roleSelect").value == delRoleId){
		     	var firstSelRoleId = null;
		     	if(areaUser.hashMap.getKey(0) != null){
		     	   firstSelRoleId = areaUser.hashMap.getKey(0).substr(8);//第一个已选择的角色id
		     	   areaUser.showNowRoleAndRightList(firstSelRoleId);
		     	}else{
		     		areaUser.showTishiDiv("提示","无法获取该角色对应的权限数据!");
		     	}
		     }
		     
		}
		else
		     areaUser.showTishiDiv("提示","不允许删除，至少保留一个角色!");
	},
	
	/**
	 * 删除或新增角色权限
	 */
	clickRoleRight : function (obj){
		var roleId = areaUser.getObj("roleSelect").value;
		var right = obj.value;
		var roleRights = areaUser.hashMap.get("orgRole_"+roleId,false);
		areaUser.checkIsAllUncheck(obj);
		
		//更新内存对应数据
		if(obj.checked){
			roleRights.push(right);
			//如果选中了模块下的权限，则其模块也要加入
			if(!areaUser.haveTheSame(roleRights,obj.parentNode.parentNode.firstChild.firstChild.id))
			   roleRights.push(obj.parentNode.parentNode.firstChild.firstChild.id);
			areaUser.hashMap.put("orgRole_"+roleId,roleRights);
			return;
		}
		for(var i=0;i<roleRights.length;i++){
			if(roleRights[i] == right){
				roleRights.splice(i, 1);
				areaUser.hashMap.put("orgRole_"+roleId,roleRights);
				break;
			}
		}
		
	},
	
	/**
	 * 点击模块
	 */
	clickRoleRightModel : function (obj){
		var roleId = areaUser.getObj("roleSelect").value;
		areaUser.checkAllOrUncheck(obj);
	},
	
	/**
	 * 点击模块 其下的checkbox全选或全部取消
	 */
	checkAllOrUncheck : function(obj){
		var select = areaUser.getObj("roleSelect");
		var roleId = select.value;
		var rightArr = areaUser.hashMap.get("orgRole_"+roleId,false);
		
		var checked = true;
		if(!obj.checked)
		    checked = false;
		var pc = obj.parentNode.parentNode.children[1];
		for(var i=0;i<pc.children.length;i++){
			pc.children[i].checked = checked;
			
			if(checked && !areaUser.haveTheSame(rightArr,pc.children[i].value)){
				rightArr.push(pc.children[i].value);
			}else{
				for(var k=0;k<rightArr.length;k++){
				    if(rightArr[k] == pc.children[i].value){
				    	rightArr.splice(k,1);
				    	break;
				    }
				}
			}
        }
        areaUser.hashMap.put("orgRole_"+roleId,rightArr);
	},
	
	/**
	 * 
	 * 内存加载时过滤没有选中的权限
	 */
	filterRoleRight : function (value){
		var roleId = areaUser.getObj("roleSelect").value;
		var roleRights = areaUser.hashMap.get("orgRole_"+roleId,false);
		for(var i=0;i<roleRights.length;i++){
			if(roleRights[i] == value){
				return "checked";
			}
		}
		return "";
	},
	
	/**
	 * 检查角色信息
	 * @return {Boolean}
	 */
	checkInfo : function(){
		if(areaUser.roleEnNames.length==0){
			areaUser.showTishiDiv("请选择相应的角色");
			return false;
		}
		return true;
	},
	
	/**
	 * 获取权限、学制信息等数据   返回格式  角色1id:权限1，权限2...-角色2id:权限1，权限2...&&&...
	 * @return {}
	 */
	getAjaxReqData : function (){
		
		var data = "";
		var dataType = "orgRole";
		if(areaUser.hashMap.keyLike(dataType)){
			data += "type:roleRight-";
			data += areaUser.swicthHashKeyVlaue(dataType);
		}
		dataType = "roleInfo";
		if(areaUser.hashMap.keyLike(dataType)){
			data += ";";
			data += "type:roleInfo-";
			data += areaUser.swicthHashKeyVlaue(dataType);
		}
		//alert(data);
		return data;
	},
	
	/**
	 * 把内存中对应的元素转换成向后台发送的数据格式
	 * @param {} dataType
	 * @return {}
	 */
	swicthHashKeyVlaue : function(dataType){
		var value = "";
		for(var i=0;i<areaUser.hashMap.size();i++){
			var key = areaUser.hashMap.getKey(i);
			if(key.substr(0,dataType.length) != dataType)
			    continue;
			var data =  areaUser.hashMap.get(key,false);
			value += (key.substr(dataType.length+1,key.length) +":" +data);
			value += "-";
		}
		value = value.substr(0,value.length-1);
		return  value;
	},
	
	/**
	 * 冻结多个用户
	 */
	frozenUsers : function (obj){
		var checkeduserIds = "";
		var checkedLoginNames = "";
		if(obj == null){//批量冻结
			checkeduserIds = areaUser.getCheckeduserIds();
			if("" == checkeduserIds){
			   areaUser.showTishiDiv("提示","请选择要冻结的用户!");
			   return;
			}
			checkedLoginNames = areaUser.getCheckedLoginNames();
		}else{//单个冻结
			checkeduserIds = areaUser.getTrIndex(obj);
			checkedLoginNames = areaUser.getTrLoginName(obj);
		}
		if(confirm("确认冻结所选用户的账号?"))
		     location.href = "manage/areaUser_frozenUsers.action?userIds="+checkeduserIds+"&loginNames="+checkedLoginNames+"&rdm="+Math.random();
	},
	
	/**
	 * 冻结多个用户
	 * @author weidai3
	 */
	reFrozenUsers : function (obj){
		var isBatch = 1;
		var checkeduserIds = "";
		var checkedLoginNames = "";
		if(obj == null){//批量冻结
			checkeduserIds = areaUser.getCheckeduserIds();
			if("" == checkeduserIds){
			   areaUser.showTishiDiv("提示","请选择要冻结的用户!");
			   return;
			}
			if(areaUser.getCheckedIsOwner()){
				areaUser.showTishiDiv("提示","不能选择当前用户,或者是超管作为冻结的用户!");
				 return;
			}
			checkedLoginNames = areaUser.getCheckedLoginNames();
		}else{//单个冻结
			isBatch=0;
			checkeduserIds = areaUser.getTrIndex(obj);
			checkedLoginNames = areaUser.getTrLoginName(obj);
		}
		if(confirm("确认冻结所选用户的账号?"))
		     location.href = "manage/areaUser_reFrozenUsers.action?userIds="+checkeduserIds+"&loginNames="+checkedLoginNames+"&isBatch="+isBatch+"&rdm="+Math.random();
	},
		
	/**
	 * 解冻
	 */
	unFrozenUser : function(obj){
		var userId = areaUser.getTrIndex(obj);
		if(confirm("确认解冻该用户的账号?"))
		     location.href = "manage/areaUser_unFrozenUser.action?userId="+userId+"&rdm"+Math.random();
	},
	
	/**
	 * 解冻
	 * @author weidai3
	 */
	unReFrozenUser : function (obj){
		var isBatch = 1;
		var checkeduserIds = "";
		var checkedLoginNames = "";
		if(obj == null){//批量解冻
			checkeduserIds = areaUser.getCheckeduserIds();
			if("" == checkeduserIds){
			   areaUser.showTishiDiv("提示","请选择要解冻的用户!");
			   return;
			}
			if(areaUser.getCheckedIsOwner()){
				areaUser.showTishiDiv("提示","不能选择当前用户,或者是超管作为解冻的用户!");
				 return;
			}
			checkedLoginNames = areaUser.getCheckedLoginNames();
		}else{//单个解冻
			isBatch = 0;
			checkeduserIds = areaUser.getTrIndex(obj);
			checkedLoginNames = areaUser.getTrLoginName(obj);
		}
		if(confirm("确认解冻所选用户的账号?"))
		     location.href = "manage/areaUser_unReFrozenUser.action?userIds="+checkeduserIds+"&loginNames="+checkedLoginNames+"&isBatch="+isBatch+"&rdm="+Math.random();
	},
	
	/**
	 * 冻结与解冻状态判断
	 * @author weidai3
	 */
	isFrozenUser : function(obj){
		var state ;
		if(state == 0){
			areaUser.unReFrozenUser(obj);
		}
		areaUser.reFrozenUsers(obj);
	},
	
	
	
	
	/**
	 * 删除多个用户
	 */
	delUsers : function (obj){
		var checkeduserIds = "";
		var checkedLoginNames = "";
		var isBatch = 1;
		if(obj == null){//批量删除
			checkeduserIds = areaUser.getCheckeduserIds();
			if("" == checkeduserIds){
			   areaUser.showTishiDiv("提示","请选择要删除的用户!");
			   return;
			}
			if(areaUser.getCheckedIsOwner()){
				areaUser.showTishiDiv("提示","不能选择当前用户,或者是超管作为删除的用户!");
				 return;
			}
			checkedLoginNames = areaUser.getCheckedLoginNames();
		}else{
			isBatch = 0;
			checkeduserIds = areaUser.getTrIndex(obj);
			checkedLoginNames = areaUser.getTrLoginName(obj);
		}
		
		$.ajax({
			type : 'post',
			url : 'manage/multipleRoles_checkUserMultipleRoleBeforeDel.action',
			data : {userIds : checkeduserIds,loginNames:checkedLoginNames},
			success : function(data){
				if(data.status != 1){
					areaUser.showTishiDiv("提示",data.msg);
					return;
				} 
				if(confirm("确认删除所选用户的账号?")){
					$("#userIds").val(checkeduserIds);
					$("#checkedLoginNames").val(checkedLoginNames);
					$("#isBatch").val(isBatch);
					$("#csrfFrom").submit();
		        }
			}
		});
		  
	},
	
	/**
	 * 重置密码
	 */
	resetPwds : function (obj,pwd){
		var checkeduserIds = "";
		var checkedLoginNames = "";
		var isBatch = 1;
		if(obj == null){//批量重置
			checkeduserIds = areaUser.getCheckeduserIds();
			if("" == checkeduserIds){
			   areaUser.showTishiDiv("提示","请选择要重置密码的用户!");
			   return;
			}
			if(areaUser.getCheckedIsAdmin()){
				areaUser.showTishiDiv("提示","不能选择超级管理员重置密码!");
				 return;
			}
			checkedLoginNames = areaUser.getCheckedLoginNames();
			
		}else{
			isBatch = 0;
			checkeduserIds = areaUser.getTrIndex(obj);
			checkedLoginNames = areaUser.getTrLoginName(obj);
		}
		
        if(confirm("您确定要将当前选择的账号密码重置为初始密码吗?\n注:所有用户的初始密码均为："+pwd)){
             $("#csrfFrom").attr("action","manage/areaUser_resetPwds.action");
             $("#userIds").val(checkeduserIds);
	         $("#checkedLoginNames").val(checkedLoginNames);
	         $("#isBatch").val(isBatch);
             $("#csrfFrom").submit();
        }
	},
	
	
	/**
	 * 按条件查询用户列表
	 */
	search : function (tj){
		
//		var role = areaUser.getObj("user_role");
	    var loginName = document.getElementById("user_loginName").value;
	    var userName = document.getElementById("user_userName").value;
	    loginName = areaUser.encode(loginName);
	    userName = areaUser.encode(userName);
//	    if(tj == "role"){
//	    	 if(role.value.length == 0){
//	    	 	areaUser.showTishiDiv("提示","无法找到对应的角色列表数据!查询无法进行!");
//	    	    return;
//	    	 }
//	         location.href = "manage/areaUser_selUser.action?type=0&role="+role.value+"&roleSelIndex="+role.selectedIndex+"&loginName="+loginName+"&userName="+userName+"&rdm="+Math.random();
//	    }
//	    else if(role != null)
//	         location.href = "manage/areaUser_selUser.action?type=1&roleSelIndex="+role.selectedIndex+"&loginName="+loginName+"&userName="+userName+"&rdm="+Math.random();
//	    else
	    	 location.href = "manage/areaUser_selUser.action?type=1&loginName="+loginName+"&userName="+userName+"&rdm="+Math.random();
	    
	},
	
	/**
	 * 查看用户
	 */
	selUser : function (obj){
	    var userId = areaUser.getTrIndex(obj);
	    location.href = "manage/areaUser_userInfo.action?userId="+userId+"&rdm="+Math.random();
	},
	
	/**
	 * 修改用户
	 */
	modifyUser : function (obj){
		var userId = areaUser.getTrIndex(obj);
	    location.href = "manage/areaUser_modifyUser.action?userId="+userId+"&rdm="+Math.random();
	},
	
	/**
	 *获取指定行所对应的 用户id
	 *@param 事件触发对象  查看 修改 冻结..
	 */
	getTrIndex : function(obj){
		var trIndex = obj.parentNode.parentNode.rowIndex ;//行号
		var $tbodyTrs = $("#table > tbody >tr");
		return document.getElementById("tr_checkbox_"+(trIndex-1)).value;
	},
	
		/**
	 *获取指定行所对应的 loginName
	 *@param 事件触发对象  查看 修改 冻结..
	 */
	getTrLoginName : function(obj){
		var trIndex = obj.parentNode.parentNode.rowIndex ;//行号
		var $tbodyTrs = $("#table > tbody >tr");
		var loginName = $("#tr_loginName_"+(trIndex-1)+"> span").attr("title");
//		return document.getElementById("tr_loginName_"+(trIndex-1)).innerHTML;
		return loginName;
		
	},
	/**
	 * 获取哪些用户被选中 用户id
	 */
	getCheckeduserIds : function (){
		var ids = "";
		var $tbodyTrs = $("#table > tbody >tr");
		for(var i = 0 ; i < $tbodyTrs.length; i++){
		    var check = document.getElementById("tr_checkbox_"+i);//$tbodyTrs[i].firstChild.firstChild;
		    if(check.checked)
		    	ids += check.value + ",";
		}
		return ids.substr(0,ids.length-1);
	},
	
	/**
	 * 获取哪些用户被选中 loginName
	 */
	getCheckedLoginNames : function (){
		var loginNames = "";
		var $tbodyTrs = $("#table > tbody >tr");
		for(var i = 0 ; i < $tbodyTrs.length; i++){
		    var check = document.getElementById("tr_checkbox_"+i);//$tbodyTrs[i].firstChild.firstChild;
		    if(check.checked){
//		    	loginNames += document.getElementById("tr_loginName_"+i).innerHTML+ ",";
		    	 loginNames += $("#tr_loginName_"+i+"> span").attr("title")+",";
		    }
		}
		return loginNames.substr(0,loginNames.length-1);
	},
	
	/**
	 * 上传文件检测
	 */
	upFileCheck : function (type){
		var filePath = null;
		if(document.getElementById("areausersFile") != null)
		    filePath = document.getElementById("areausersFile").value;
		else if(document.getElementById("upHeadImg") != null)
		    filePath = document.getElementById("upHeadImg").value;
		  
		var index = filePath.lastIndexOf(".");//最后一个.出现的索引
		var fileEnd = filePath.substring(index+1,filePath.length).toUpperCase();//获取上传文件的后缀
		switch(type){
			case 0: {
				if(fileEnd != "XLS" && fileEnd != "XLSX"){
					areaUser.showTishiDiv("提示","批量账号导入文件必须是xls或xlsx文件!");
					return false;
				}
				break;
			}
			case 1: {
				if(filePath.length > 0){
					if(fileEnd != "PNG" && fileEnd != "JPG" && fileEnd != "JPEG" && fileEnd != "BMP"){
						alert("头像文件必须是png|jpg等图片格式文件!");
						return false;
					}
					
					if(document.getElementById("areausersFile").files[0].size>2*1024*1024){
						alert("头像文件文件必须小于2MB!");
						return false;
					}
						
				}
				break;
			}
		}
		
	   return true;
	},
	
	
	/**
	 * 批量导入
	 */
	batchImport : function(){
		areaUser.showDiv("batchImport");
	},
	
	/**
	 * 上传头像
	 */
	headImg : function (){
		window.open('manage/areaUser_tzUpImg.action?rdm='+Math.random(),'','width=550,height=200,left=500,top=250,location=no,menubar=no,status=no,toolbar=no');
	},
	
	
	
	/**
	 * 上传批量导入文件
	 */
	uploadBatchFile : function(){
		if($("#areausersFile").val().length == 0){
			//areaUser.showTishiDiv("提示","请选择批量导入文件!");
			alert("请选择批量导入文件!");
			return;
		}
		
		if(!areaUser.upFileCheck(0))
		   return;
		   
	    var form = document.getElementById("upFile_form");
	    var div = document.getElementById("batchImport");
	    div.style.display = "none";
	    
	    $("#submitButton").attr("disabled", "disabled");
		areaUser.pageDisbale();
		areaUser.showWaitDiv();
		// 通过ajax提交form表单，根据返回值，下载错误页面。
		
	    form.submit();
	},
	
		/**
	 * 上传头像文件
	 */
	uploadHeadImgFile : function(){
		if($("#areausersFile").val().length == 0){
			alert("请选择头像文件!");
			return;
		}
		if(!areaUser.upFileCheck(1))
		   return;
		   
	    var form = document.getElementById("upFile_form");
	    var div = document.getElementById("upHeadImgDiv");
	    div.style.display = "none";
	    
	    
		areaUser.pageDisbale();
		areaUser.showWaitDiv();
	    form.submit();
	    //window.close();
	},
	
	
	/*************************************************新增用户****************************************************/
	
	/**
	 * 检查 保存条件是否通过
	 */
	checkRequest : function(isModify){
	    if($.trim($("#loginName").val()).length == 0){
	    	areaUser.showTishiDiv("提示","请输入账号!");$("#loginName").focus();return false;
	    }
//	    if($.trim($("#nickName").val()).length == 0){
//	    	areaUser.showTishiDiv("提示","请输入昵称!");$("#nickName").focus();return false;
//	    }
	    if($.trim($("#realName").val()).length == 0){
	    	areaUser.showTishiDiv("提示","请输入姓名!");$("#realName").focus();return false;
	    }
	    
	    if(isModify == null){
		    if($.trim($("#pwd").val()).length == 0 && $.trim($("#repwd").val()).length == 0){
		    	//判断密码不能全为空格
			    var regSpace = new RegExp(/[ ]+/);
			    if(regSpace.test($("#pwd").val())){
			    	areaUser.showTishiDiv("密码提示",commonPasswordCheck.getPasswordRegText());
			    	return false;
			    }
		    	document.getElementById("pwd").value = "";
			    document.getElementById("repwd").value = "";
		    }
		    
		    if($("#pwd").val() != $("#repwd").val()){
		    	areaUser.showTishiDiv("提示","两次输入的密码不一致!");$("#pwd").focus();
		    	return false;
		    }
//		    if($.trim($("#pwd").val()).length != 0 && $.trim($("#repwd").val()).length != 0){
//			    var reg = new RegExp(/^\w{6,16}$/);
//			    if(!reg.test($.trim($("#pwd").val()))){
//		    		areaUser.showTishiDiv("提示","密码只能是6到16位的字母、数字、下划线组成!");
//		    		return false;
//		    	}
//		    }
		    if($("#pwd").val().length != 0 && $("#repwd").val().length != 0){
		    	if(!commonPasswordCheck.checkPassword($("#pwd").val())){
		    		areaUser.showTishiDiv("密码提示",commonPasswordCheck.getPasswordRegText());$("#pwd").focus();return false;		    		
		    	}
			    
		    }
	    }
	    
//	    var im = areaUser.getObj("im").value;
//	    var reg =/^[0-9]*$/; 
//	    if($('#im').val().length>0){
//	    	
//	    	if(!reg.test($('#im').val())){
//	    		areaUser.showTishiDiv("提示","请正确填写QQ！");
//	    		return false;
//	    	}
//	    }
	    
	    
	    
//	    var reg = new RegExp("^[0-9]*$");//是否是数字正则
//        var obj = document.getElementById("workingAge");
//	    if(!reg.test(obj.value)){
//	    	areaUser.showTishiDiv("提示","输入的工龄值不合法!");return false;
//	    }
	    
	    obj = document.getElementById("email");//邮箱正则
	    
	    if(obj.value.length > 0){
		    reg = new RegExp(/^[0-9a-z]([._]?[0-9a-z])+@([0-9a-z][-\w]*[0-9a-z]\.)+[a-z]{2,9}$/);//不能加引号
		    if(!reg.test(obj.value.toLowerCase())){
		    	areaUser.showTishiDiv("提示","输入的邮箱地址不合法!");return false;
		    }
	    }
	    
	  /*  obj = document.getElementById("mobile");//手机
	    if(obj.value.length > 0){
		    reg = new RegExp(/^([\d-+]*)$/);//不能加引号
		    if(!reg.test(obj.value)){
		    	areaUser.showTishiDiv("提示","输入的手机号码不合法!");return false;
		    }
	    }*/
	    
	    obj = document.getElementById("mobile");//手机电话
	    if(obj.value.length > 0){
		    reg = new RegExp(/^[1][3587][0-9]{9}$/);//不能加引号
		    if(!reg.test(obj.value)){
		    	areaUser.showTishiDiv("提示","输入的手机号码不合法!");return false;
		    }
	    }
	    
	  
	    
		    
	     
	     obj = document.getElementById("idCardNo");// 身份证正则
	     if(obj.value.length==0){
	    	 areaUser.showTishiDiv("提示","请输入身份证!");return false; 
	     }
		    if(obj.value.length > 0){
//			    reg = new RegExp(/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/);// 不能加引号
//		    	reg = new RegExp(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X)$)/);
		    	// 老身份证15位正则
		    	var idCardof15Reg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
		    	// 新身份证18位正则
		    	var idCardof18Reg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
			    if(!idCardof15Reg.test(obj.value)&&(!idCardof18Reg.test(obj.value))){
//			    if(!reg.test(obj.value)){
			    	areaUser.showTishiDiv("提示","输入的身份证不合法!");return false;
			    }
		    }
		    

		    
		    obj = document.getElementById("idCardNo");//身份证号
		     var cacheValue = areaUser.cacheHashMap.get("idCardNo",false);
		     if(obj.value.length > 0 && obj.value != cacheValue){
		     	if(!areaUser.checkIdCardNo())
		            return false;
		     }  
		     
		     obj = document.getElementById("email");//邮箱正则
			    var cacheValue = areaUser.cacheHashMap.get("email",false);
			     if(obj.value.length > 0 && obj.value != cacheValue){
			     	if(!areaUser.checkEmai())
			            return false;
			     }
		    
		    
		  obj = document.getElementById("mobile");//手机号码
	    cacheValue = areaUser.cacheHashMap.get("mobile",false);
	     if(obj.value.length > 0 && obj.value != cacheValue){
	     	if(!areaUser.checkPhone())
                return false;
	     }
         if(isModify == null){
        	 if(!areaUser.checkAccountgeshi())
        		 return false;
         }
	         
	     if(!areaUser.checkLength())
	         return false;
	         
//	     if(!areaUser.checkInfo()){
//	         return false;
//	     }
	    
	    if(isModify == null)//说明是  新增检测
	        return areaUser.checkAccount();
	        
	},
	
	/**
	 * 检查账号格式   只能是字母数字下划线
	 */
	checkAccountgeshi : function(){
		/**
		var value = $("#loginName").val();
		var reg = new RegExp("^[a-zA-Z0-9_@]+$");
		//var reg = new RegExp("^([\u4E00-\uFA29]|[\uE7C7-\uE7F3]|[a-zA-Z0-9])*$");//不能加引号   
		if(!reg.test(value)){
			areaUser.showTishiDiv("提示","用户名只能是字母、数字或下划线或@符号!");return false;
		}
		return true;
		*/
		var value = $("#loginName").val();
		var reg = new RegExp("^[a-zA-Z0-9_@]{2,18}$");//不能加引号
		var regTel = new RegExp("^1[0-9]{10}$"); // 手机号
		var regEmail = new RegExp("^[0-9a-z]([._]?[0-9a-z])+@([0-9a-z][-\w]*[0-9a-z]\.)+[a-z]{2,9}$"); //邮箱
		if(!reg.test(value)||(regTel.test(value))||(regEmail.test(value))){
//		if(!reg.test(value)){
			areaUser.showTishiDiv("提示","用户名只能2-18位的字母、数字或下划线@符号且不能为手机号与邮箱账户!");return false;
		}
		return true;
	},
	
	/**
	 * 检查该账号是否已被使用
	 */
	checkAccount : function(){
		var loginName = $("#loginName").val();
		if($.trim(loginName).length == 0)
			return false;
			
	    var resultObj =$.ajax({url:"manage/areaUser_userAccountIsRepeat.action?loginName="+loginName+"&rdm="+Math.random(),async:false});
    	var operResult  = eval('(' + resultObj.responseText + ')');
    	if(1 == operResult.status){
    		areaUser.showTishiDiv("提示",operResult.msg);
//    		var userId = areaUser.ajax("manage/areaUser_getUserIdByAccount.action?account="+loginName);
//    		if (userId != null) {
//    			$('#multiIdentitySelector').show();
//    			$('#existedUserId').val(userId);
//    		}
//    		$('#multiIdentitySelector').hide();
    		return false;
    	}
    	else{
//    		$('#multiIdentitySelector').hide();
    		return true;
    	}
    		
		
	},
	
	/**
	 * 检查Email是否已被使用
	 */
	checkEmai : function(){
		var email = $("#email").val();
		var  userId = $("#userId").val();
		if($.trim(email).length == 0)
			return false;
			
	    var resultObj =$.ajax({url:"manage/areaUser_emailIsRepeat.action?email="+email+"&userId="+userId+"&rdm="+Math.random(),async:false});
    	var operResult  = eval('(' + resultObj.responseText + ')');
    	if(1 == operResult.status){
    		areaUser.showTishiDiv("提示",operResult.msg);
    		return false;
    	}
    	else
    		return true;
		
	},
	
		
	/**
	 * 检查电话是否已被使用
	 */
	checkPhone : function(){
		var mobile = $("#mobile").val();
		var  userId = $("#userId").val();
		if($.trim(mobile).length == 0)
			return false;
			
	    var resultObj =$.ajax({url:"manage/areaUser_mobileIsRepeat.action?mobile="+mobile+"&userId="+userId+"&rdm="+Math.random(),async:false});
    	var operResult  = eval('(' + resultObj.responseText + ')');
    	if(1 == operResult.status){
    		areaUser.showTishiDiv("提示",operResult.msg);
    		return false;
    	}
    	else
    		return true;
		
	},
	/**
	 * 检查身份证号是否已经被使用
	 */
	checkIdCardNo : function(){
		var  idCardNo = $("#idCardNo").val();
		var  userId = $("#userId").val();
		if($.trim(idCardNo).length==0){
			return false;
		}
		var resultObj =$.ajax({url:"manage/areaUser_idCardNoIsRepeat.action?idCardNo="+idCardNo+"&userId="+userId+"&rdm="+Math.random(),async:false});
	    var operResult  = eval('(' + resultObj.responseText + ')');
	    	if(1 == operResult.status){
	    		areaUser.showTishiDiv("提示",operResult.msg);
//	    		var userId = areaUser.ajax("manage/areaUser_getUserIdByAccount.action?idCardNo="+idCardNo);
//	    		if (userId != null) {
//	    			$('#multiIdentitySelector').show();
//	    			$('#existedUserId').val(userId);
//	    		}
	    		return false;
	    	}
	    	else{
//	    		$('#multiIdentitySelector').hide();
	    		return true;
	    	}
	},
	
	/**
	 * 缓存邮箱地址和电话号码
	 */
	modifyInitPhoneAndEmail : function(){
		//var mobile = areaUser.getObj("mobile").value;
		var email = areaUser.getObj("email").value;
		//areaUser.cacheHashMap.put("mobile",mobile);
		areaUser.cacheHashMap.put("email",email);
	},
	
	
	/**
	 * 长度检测
	 */
	checkLength : function(){
		var valueArr = new Array();
		var lengthArr = new Array();
		var nameArr = new Array();
		
		var loginName = areaUser.getObj("loginName").value;//用户名 100
		var pwd = null;
		if(areaUser.getObj("pwd") != null)
		    pwd = areaUser.getObj("pwd").value;//密码 255
		var realName = areaUser.getObj("realName").value;//姓名 20
		var email = areaUser.getObj("email").value;//email 255
//		var mobile = sysUser.getObj("mobile").value;//手机20
//		var phone = areaUser.getObj("phone").value;//电话20
		var homeAddress = areaUser.getObj("homeAddress").value;//地址 255
		var description = areaUser.getObj("description").value;//简介255
		
		var nation = areaUser.getObj("nation").value; // 民族
		var nationality = areaUser.getObj("nationality").value; // 国籍
		var nativePlace = areaUser.getObj("nativePlace").value; // 籍贯
//		var QQ = areaUser.getObj("im").value;//QQ 20 
		
		
		valueArr.push(loginName);valueArr.push(pwd);
		valueArr.push(realName);
		valueArr.push(email);
//		valueArr.push(phone);
		valueArr.push(homeAddress);valueArr.push(description);
		valueArr.push(nation);
		valueArr.push(nationality);
		valueArr.push(nativePlace);
//		valueArr.push(QQ);
		
		
		
		lengthArr.push(80);lengthArr.push(255);
		lengthArr.push(20);
		lengthArr.push(255);
//		lengthArr.push(20);
		lengthArr.push(80);lengthArr.push(80);
		lengthArr.push(20);
		lengthArr.push(20);
		lengthArr.push(20);
		lengthArr.push(20);
		
		nameArr.push("账号");nameArr.push("密码");
		nameArr.push("姓名");
		nameArr.push("电子邮件");
//		nameArr.push("办公电话");
		nameArr.push("家庭地址");nameArr.push("个人简介");
		nameArr.push("民族"); 
		nameArr.push("国籍"); 
		nameArr.push("籍贯"); 
//		nameArr.push("QQ"); 
		
		
		
		for(var i=0;i<valueArr.length;i++){
			if(valueArr[i] == null)
			    continue;
			if(valueArr[i].length > lengthArr[i]){
				areaUser.showTishiDiv("提示",nameArr[i]+"长度不能超过"+lengthArr[i]);
				return false;
			}
		}
		
		return true;
	},


	/**
	 * 提交新增用户form表单
	 */
	submitInfo : function (){
		var len = $('.subjectandphases').length;
		if (len == 0) {
			areaUser.showTishiDiv("提示","请选择学段-学科信息！");
			return false;
		}
		var subject = $("#subjectSelect option:selected").text();
		var subandphase = '';
		$('.subandphaseresult').each(function(index, cur) {
			var v = $(cur).attr('code');
			subandphase = subandphase + v + ',';
		});
		var phase = $("#phaseSelect option:selected").text();
		document.addUserForm.action = "manage/areaUser_insertUsers.action?&rmd="+Math.random()
		+"&subject="+subandphase;
		return areaUser.checkRequest();
	},
	
	
	
	/***************************************************修改用户**************************************/
	submitInfo_modify : function (){
		var len = $('.subjectandphases').length;
		if (len == 0) {
			areaUser.showTishiDiv("提示","请选择学段-学科信息！");
			return false;
		}
		var subject = $("#subjectSelect option:selected").text();
		var subandphase = '';
		$('.subandphaseresult').each(function(index, cur) {
			var v = $(cur).attr('code');
    		subandphase = subandphase + v + ',';
    	});
		document.modifyUserForm.action="manage/areaUser_updateUser.action?rdm="+Math.random()
		                                               +"&subject="+subandphase;
		return areaUser.checkRequest(true);
	},
	
	
	
	
	/***************************************************页面功能******************************************/
	/**
	 * 页面遮罩
	 */
	pageDisbale : function(){
	    var zzDiv = document.createElement("div");
	    zzDiv.id = "zhezhaoDiv";
	    zzDiv.style.position = 'absolute';
	    zzDiv.style.top = 0;
        zzDiv.style.left = 0;
        zzDiv.style.width = document.body.offsetWidth+"px";
        zzDiv.style.height = document.body.offsetHeight+"px";
        zzDiv.style.backgroundColor = "#C0C0C0";
        zzDiv.style.mozOpacity = "0.2";
        zzDiv.style.opacity = ".20";
        zzDiv.style.filter = "alpha(opacity=20)";
        zzDiv.style.zIndx = "10000";
        document.body.appendChild(zzDiv);
	},
	
	/**
	 * 让页面恢复可用
	 */
	pageAble : function(){
		document.body.removeChild(document.getElementById("zhezhaoDiv"));
	},
	/**
	 * 显示div
	 */

	/**
	 * 文本提示div
	 * @param {} title 标题
	 * @param {} content 正文
	 */
	showTishiDiv : function(title,content){
		var title_obj = document.getElementById("tishi_title");
		var content_obj = document.getElementById("tishi_content");
		title_obj.innerHTML = title;
		content_obj.innerHTML = content;
		areaUser.showDiv("tishiDiv");
	},
	/**
	 * 提示等待 div
	 */
	showWaitDiv : function(){
		var div = document.getElementById("uploadwaitdiv");
		div.style.display = "block";
	},
	
	showDiv : function(id){
	$('#'+id).modal({
        keyboard: false,
        backdrop: false
    });
	var div = document.getElementById(id);
    div.style.display = "block";
	},
	
	
   	/**
   	 * chechBox全选
   	 */
	allCheck : function(){
		var isAllcheck = false;
		var $tbodyTrs = $("#table > tbody >tr");
		if($tbodyTrs.length > 0){
			isAllcheck = !document.getElementById("tr_checkbox_0").checked;
			for(var i = 0 ; i < $tbodyTrs.length; i++){
			    document.getElementById("tr_checkbox_"+i).checked = isAllcheck;
			}
		}
		document.getElementById("checkall").checked = isAllcheck;
	},
	/**
	 * 取消checkBox全选中
	 */
	clearAllCheck : function (){
		var $tbodyTrs = $("#table > tbody >tr");
		for(var i = 0 ; i < $tbodyTrs.length; i++)
		    document.getElementById("tr_checkbox_"+i).checked = false;
		
		
	},
	/**
	 *  全选或全部取消选中
	 */
	checkAllorClear : function (){
		if(document.getElementById("checkall").checked)
			areaUser.allCheck();
		else
			areaUser.clearAllCheck();
	},
	
	/**
	 * select 根据其值返回文本
	 * @param {} value
	 * @param {} selId
	 * @return {}
	 */
	SelGetTextByValue : function(value,selId){
		if(value == "0" || value == 0)
		   return "";
		   
		var select = areaUser.getObj(selId);
		for(var i=0;i<select.options.length;i++){
			if(select.options[i].value == value)
				 return select.options[i].text;
		}
		
	},
	/**
	 * 判断一个checkbox组是否都没全中
	 * @param {} checkobj
	 * @return {Boolean}
	 */
	checkIsAllUncheck : function (checkobj){
		var parent = checkobj.parentNode;
		var isAllUnckeck = true;
		for(var i=0;i<parent.children.length;i++){
			if(parent.children[i].checked){
				isAllUnckeck = false;
			    break;
			}
		}
		if(isAllUnckeck)
		    parent.parentNode.firstChild.firstChild.checked = false;
		else
		    parent.parentNode.firstChild.firstChild.checked = true;
	},
	
	viewManageInfo : function(userId){
		var url = "manage/sysUser_viewManageInfo.action"
			+ "?roleEnName=instructor&userId=" + userId+"&type=1"//用户ID	
			;
		$.layer({
			type : 2,
			shade : [0.5,'#fff',true],
		    fix: false,
			title : ['设置管理员',true],
			iframe : {src : url},
			area : ['400px' , '200px'],
			offset : ['100px', ''],
			closeBtn : [0,true],
			border:[2 , 0.3 , '#000', true],		
			bgcolor : '#e0e0e0',
			close : function(index){				
				layer.close(index);
			}
		});
	},
	
	
	
	/**
	 * 初始化检测有无模块下的chekckbox全部没选中  有的话该模块的checkbox取消选中
	 */
	initCheckIsAllUncheck  : function(){
	    var rightListDiv = areaUser.getObj("rightListDiv");
		for(var i=0;i<rightListDiv.children.length;i++){
			var div = rightListDiv.children[i];
			var pa = div.children[0];
			var pc = div.children[1];
			var allUnchecked = true;
			for(var k=0;k<pc.children.length;k++){
				if(pc.children[k].checked){
				    allUnchecked = false;
				    break;
				}
			}
			if(allUnchecked)
			   pa.children[0].checked = false;
			
		}
	},
	
	getObj : function(id){
		if(document.getElementById(id) == null)
		   return null; 
		else
		   return document.getElementById(id);
	},
	
	/**
	 * ajax请求
	 * @param {} url
	 * @return {}
	 */
	ajax : function (url){
		var resultObj =$.ajax({url:url,async:false});
		//alert(url+"\n"+resultObj.responseText);
		var operResult  = eval('(' + resultObj.responseText + ')');
		if(1 == operResult.status){
			if(operResult.data.length <= 1)//"]"
			   return null;
			return operResult.data;
		}else
		    return null;
	},
	
	//编码中文，解决乱码
	encode : function(value){
		return encodeURI( encodeURI(value));
	},
	
	subShow : function(text,length){
		if(text.length > length)
			return text.substring(0,length)+"...";
		else
			return text;
	},
	/**
	 * 获取哪些用户被选中，并判断是不是当前用户。
	 */
	getCheckedIsOwner : function (){
		var loginUserId = $("#loginUserId").val();
		var sysadmin = $("#sysName").val();
		var ids = "";
		var $tbodyTrs = $("#table > tbody >tr");
		for(var i = 0 ; i < $tbodyTrs.length; i++){
		    var check = document.getElementById("tr_checkbox_"+i);//$tbodyTrs[i].firstChild.firstChild;
		    if(check.checked){
		    	var loginName = $("#tr_loginName_"+i+"> span").attr("title");
		    	if(sysadmin==loginName){
		    		return true;
		    	}
		    	if(check.value==loginUserId){
		    		return true;
		    	}
		    }
		}
		return false;
	},
	/**
	 * 获取哪些用户被选中，并判断是不是当前用户。
	 */
	getCheckedIsAdmin : function (){
		var loginUserId = $("#loginUserId").val();
		var sysadmin = $("#sysName").val();
		var ids = "";
		var $tbodyTrs = $("#table > tbody >tr");
		for(var i = 0 ; i < $tbodyTrs.length; i++){
		    var check = document.getElementById("tr_checkbox_"+i);//$tbodyTrs[i].firstChild.firstChild;
		    if(check.checked){
		    	var loginName = $("#tr_loginName_"+i+"> span").attr("title");
		    	if(sysadmin==loginName){
		    		return true;
		    	}
		    }
		    	
		}
		return false;
	}
	
	
};